//
//  RecommendGameView.m
//  YuDou
//
//  Created by qiupeng on 2018/6/24.
//  Copyright © 2018年 yingqi. All rights reserved.
//

#import "RecommendGameView.h"
#import "CollectionGameCell.h"

#import "BaseModel.h"

static NSString *GameCellID = @"GameCellID";
static CGFloat kEdgeInsetMargin  = 10;

@interface RecommendGameView()<UICollectionViewDataSource,UICollectionViewDelegate>

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;

@end


@implementation RecommendGameView


+ (instancetype)recommendGameView
{
    return [[[NSBundle mainBundle] loadNibNamed:@"RecommendGameView" owner:nil options:nil] firstObject];
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    
    self.autoresizingMask = UIViewAutoresizingNone;
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    [self.collectionView registerNib:[UINib nibWithNibName:@"CollectionGameCell" bundle:nil] forCellWithReuseIdentifier:GameCellID];
    self.collectionView.contentInset = UIEdgeInsetsMake(0, kEdgeInsetMargin, 0, kEdgeInsetMargin);

}

- (void)setGroups:(NSArray<AnchorGroup *> *)groups
{
    _groups = groups;
    [self.collectionView reloadData];
}


#pragma mark - CollecetionView DataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _groups.count ? _groups.count : 0;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CollectionGameCell *cell = (CollectionGameCell *)[collectionView dequeueReusableCellWithReuseIdentifier:GameCellID forIndexPath:indexPath];
    cell.game = _groups[indexPath.item];
    return cell;
}
@end
